import java.util.Locale;

/**
 * Created with IntelliJ IDEA
 * Description:String对象的比较
 * User:恋恋
 * Date:2022-10-07
 * Time:16:40
 */
public class TestDemo2 {
    public static void main(String[] args) {
        String str1 ="hello";
        String str2="hello";
        String str3 = new String("hello");
        String str4 = new String("hello");
        str3=new String("word");//
        System.out.println(str3);

        System.out.println(str1 == str2);
        System.out.println(str1 == str4);
        System.out.println(str3==str4);



        int a = 10;
        int b = 10;
        int c = 30;
        System.out.println("===对于基本数据类型，==比较的是变量中的值===");
        System.out.println(a == b);
        System.out.println(a == c);
        System.out.println("===对于引用类型 == 比较的是引用中的地址===");










        System.out.println("=======equals方法======");
        System.out.println(str1.equals(str2));
        System.out.println("=======compareTo方法======");
        System.out.println(str1.compareTo(str3));//104-119=-15
        System.out.println(str1.compareTo(str4));
        System.out.println("==============================");
        String s = "aaabbbcccaaabbbccc";
        System.out.println(s.charAt(3)); // 'b'
        System.out.println(s.indexOf('c')); // 6
        System.out.println(s.indexOf('c', 10)); // 15
        System.out.println(s.indexOf("bbb")); // 3
        System.out.println(s.indexOf("bbb", 10)); // 12
        System.out.println(s.lastIndexOf('c')); // 17
        System.out.println(s.lastIndexOf('c', 10)); // 8
        System.out.println(s.lastIndexOf("bbb")); // 12
        System.out.println(s.lastIndexOf("bbb", 10)); // 3
        System.out.println("==========数字转字符串==========");
        String s1 = String.valueOf(1234);
        System.out.println(s1);
        System.out.println("==========字符串转数字==========");
        int nums = Integer.parseInt("123");
        System.out.println(nums);
        System.out.println("=============");
        String str = "hello";
        String str8 = "HELLO";
        //小写-》大写
        System.out.println(str.toUpperCase());
        //大写-》小写
        System.out.println(str8.toLowerCase());
        System.out.println("==========================");
        String sc = "hello";
        // 字符串转数组
        char[] ch = s.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            System.out.print(ch[i]);
        }
        System.out.println();
        // 数组转字符串
        String s2 = new String(ch);
        System.out.println(s2);
        System.out.println("=========================");
        String str6 = String.format("%d-%d-%d", 2022, 10, 8);
        System.out.println(str6);
        System.out.println("========================");
        String str7 = "hello";
        //字符串转数组
        char[] ch1 = str7.toCharArray();
        for (char i : ch1) {
            System.out.print(i + " ");
        }
        System.out.println();
        //数组转字符串
        String str9 = new String(ch1);
        System.out.println(str9);
        System.out.println("==========================");
        String str10 = "hello word";
        System.out.println(str10.replaceAll("l", "m"));
        System.out.println(str10.replaceFirst("l", "m"));
        System.out.println("===============");
        System.out.println("=================================");
        String str12 = "hello world hello bit";
        String[] result = str12.split(" ", 2);
        for (String w : result) {
            System.out.println(w);

        }
        System.out.println("===============");
        String str13 = "192.168.1.1" ;
        String[] result9 = str13.split("\\.") ;
        for(String w: result9) {
            System.out.println(w);
        }
        String o=new String("a")+new String("b");
        System.out.println(o);

    }
}
